﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrayParrot.Core;

namespace FimetContoDeposito.BLL
{
    public class Result<T>
    {
        public Exception Error { internal set; get; }
        public string Message { internal set; get; }
        public T Value { internal set; get; }

        public Result()
        {
        }
    }

    public static class ReturnValueHelper<T>
    {
        public static Result<T> Check(ReturnValue<T> returnValue)
        {
            Result<T> retValue = null;

            if (returnValue.HasValue)
            {
                retValue.Message = returnValue.Message;
                retValue.Value = returnValue.Value;
            }
            else
            {
                if (!returnValue.HasValue)
                {
                    retValue.Message = returnValue.Message;
                    retValue.Value = default(T);
                }
                else
                {
                    if (returnValue.HasError)
                    {
                        retValue.Error = returnValue.Error;
                        retValue.Message = returnValue.Error.Message;
                        retValue.Value = default(T);
                    }
                }
            }

            return retValue;
        }
    }
}
